//
//  DKPanCardAuthCell.m
//  DanKU
//
//  Created by 吴斌 on 2023/11/5.
//

#import "DKPanCardAuthCell.h"
#import "DKPanCardSigleView.h"

static NSString * DKPanCardAuthCellId = @"DKPanCardAuthCellId";
@interface DKPanCardAuthCell()
@property (nonatomic, strong)UIView * dk_PanCardBgView;
@property (nonatomic,strong) UIButton *dk_PanCardBtn;
@end
@implementation DKPanCardAuthCell
+ (instancetype)authPanCardAuthCell:(UITableView *)tableView{
    DKPanCardAuthCell * dk_PanCardAuthCell = [tableView dequeueReusableCellWithIdentifier:DKPanCardAuthCellId];
    if (!dk_PanCardAuthCell) {
        dk_PanCardAuthCell = [[DKPanCardAuthCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DKPanCardAuthCellId];
    }
    dk_PanCardAuthCell.backgroundColor = [UIColor clearColor];
    dk_PanCardAuthCell.selectionStyle = UITableViewCellSelectionStyleNone;
    dk_PanCardAuthCell.accessoryType = UITableViewCellAccessoryNone;
    return dk_PanCardAuthCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    self.dk_PanCardBgView = [[UIView alloc] init];
    self.dk_PanCardBgView.backgroundColor = [UIColor whiteColor];
    self.dk_PanCardBgView.layer.cornerRadius = DK_IsWidthScale(50);
    self.dk_PanCardBgView.clipsToBounds = YES;
    [self.contentView addSubview:self.dk_PanCardBgView];
    [self.dk_PanCardBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(20)));
        make.bottom.equalTo(@(-DK_IsWidthScale(0)));
    }];
    UIView * dk_PanCardBottomView = [[UIView alloc] init];
    dk_PanCardBottomView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:dk_PanCardBottomView];
    [dk_PanCardBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.bottom.equalTo(@(-DK_IsWidthScale(0)));
    }];
    
    UILabel * dk_AuthCardHeadLab = [[UILabel alloc] init];
    dk_AuthCardHeadLab.textColor = DK_Hex(@"#333333");
    dk_AuthCardHeadLab.text = @"PAN Card Front";
    dk_AuthCardHeadLab.font = DK_FONT_Medium(14);
    dk_AuthCardHeadLab.textAlignment = NSTextAlignmentCenter;
    [self.dk_PanCardBgView addSubview:dk_AuthCardHeadLab];
    [dk_AuthCardHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(38)));
        make.height.equalTo(@(DK_IsWidthScale(20)));
    }];
    UILabel * dk_AuthCardHeadAlertLab = [[UILabel alloc] init];
    dk_AuthCardHeadAlertLab.textColor = DK_Hex(@"#999999");
    dk_AuthCardHeadAlertLab.text = @"Please take the front photo of your PAN Card";
    dk_AuthCardHeadAlertLab.font = DK_FONT_Regular(12);
    dk_AuthCardHeadAlertLab.textAlignment = NSTextAlignmentCenter;
    [self.dk_PanCardBgView addSubview:dk_AuthCardHeadAlertLab];
    [dk_AuthCardHeadAlertLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(dk_AuthCardHeadLab.mas_bottom).offset(DK_IsWidthScale(8));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
    UIImageView * dk_AuthCardCenterImgView = [[UIImageView alloc] init];
    dk_AuthCardCenterImgView.userInteractionEnabled = YES;
    dk_AuthCardCenterImgView.image = DK_GetImage(@"dk_AuthCardCenterIcon");
    [self.dk_PanCardBgView  addSubview:dk_AuthCardCenterImgView];
    [dk_AuthCardCenterImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.dk_PanCardBgView);
        make.top.equalTo(dk_AuthCardHeadAlertLab.mas_bottom).offset(DK_IsWidthScale(26));
        make.width.equalTo(@(DK_IsWidthScale(147)));
        make.height.equalTo(@(DK_IsWidthScale(146)));
    }];
    UIButton * dk_AuthCardCenterBtn = [[UIButton alloc] init];
    [dk_AuthCardCenterBtn addTarget:self action:@selector(startPanCard) forControlEvents:UIControlEventTouchUpInside];
    [dk_AuthCardCenterImgView addSubview:dk_AuthCardCenterBtn];
    [dk_AuthCardCenterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(DK_IsWidthScale(0)));
    }];
    CGFloat panCardSigleX = (DK_SCREEN_W - DK_IsWidthScale(76)*3 - DK_IsWidthScale(12)*2)/2;
    DKPanCardSigleView *dk_PanCardBlurredView = [[DKPanCardSigleView alloc] init];
    dk_PanCardBlurredView.panCardName = @"Blurred";
    [self.dk_PanCardBgView  addSubview:dk_PanCardBlurredView];
    [dk_PanCardBlurredView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(panCardSigleX));
        make.top.equalTo(dk_AuthCardCenterImgView.mas_bottom).offset(DK_IsWidthScale(33));
        make.width.equalTo(@(DK_IsWidthScale(76)));
        make.height.equalTo(@(DK_IsWidthScale(48)));
    }];
    DKPanCardSigleView *dk_PanCardIncompleteView = [[DKPanCardSigleView alloc] init];
    dk_PanCardIncompleteView.panCardName = @"Incomplete";
    [self.dk_PanCardBgView  addSubview:dk_PanCardIncompleteView];
    [dk_PanCardIncompleteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dk_PanCardBlurredView.mas_right).offset(DK_IsWidthScale(12));
        make.top.equalTo(dk_AuthCardCenterImgView.mas_bottom).offset(DK_IsWidthScale(33));
        make.width.equalTo(@(DK_IsWidthScale(76)));
        make.height.equalTo(@(DK_IsWidthScale(48)));
    }];
    DKPanCardSigleView *dk_PanCardOverexposedView = [[DKPanCardSigleView alloc] init];
    dk_PanCardOverexposedView.panCardName = @"Overexposed";
    [self.dk_PanCardBgView addSubview:dk_PanCardOverexposedView];
    [dk_PanCardOverexposedView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dk_PanCardIncompleteView.mas_right).offset(DK_IsWidthScale(12));
        make.top.equalTo(dk_AuthCardCenterImgView.mas_bottom).offset(DK_IsWidthScale(33));
        make.width.equalTo(@(DK_IsWidthScale(76)));
        make.height.equalTo(@(DK_IsWidthScale(48)));
    }];
    self.dk_PanCardBtn = [[UIButton alloc] init];
    [self.dk_PanCardBtn setTitle:@"PAN Card" forState:UIControlStateNormal];
    [self.dk_PanCardBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
    self.dk_PanCardBtn.titleLabel.font = DK_FONT_Semibold(16);
    [self.dk_PanCardBtn setBackgroundImage:DK_GetImage(@"dk_registerNextSelectBg") forState:UIControlStateNormal];
    [self.dk_PanCardBtn addTarget:self action:@selector(startPanCard) forControlEvents:UIControlEventTouchUpInside];
    [self.dk_PanCardBgView addSubview:self.dk_PanCardBtn];
    [self.dk_PanCardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.top.equalTo(dk_PanCardOverexposedView.mas_bottom).offset(DK_IsWidthScale(62));
    }];
    UIButton * dk_AuthCardPrivacyAgreementBtn = [[UIButton alloc] init];
    [dk_AuthCardPrivacyAgreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [dk_AuthCardPrivacyAgreementBtn setTitleColor:DK_Hex(@"#CCCCCC") forState:UIControlStateNormal];
    dk_AuthCardPrivacyAgreementBtn.titleLabel.font = DK_FONT_Regular(12);
    [dk_AuthCardPrivacyAgreementBtn addTarget:self action:@selector(checkCardPrivacyAgreement) forControlEvents:UIControlEventTouchUpInside];
    [self.dk_PanCardBgView addSubview:dk_AuthCardPrivacyAgreementBtn];
    [dk_AuthCardPrivacyAgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.dk_PanCardBgView);
        make.top.equalTo(self.dk_PanCardBtn.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
//    [self layoutIfNeeded];
//    [self.dk_PanCardBgView makeCornerOnTopleftRight:DK_IsWidthScale(50)];
}
- (void)checkCardPrivacyAgreement{
    if(self.CheckPrivaryAgmentBlock){
        self.CheckPrivaryAgmentBlock();
    }
}
- (void)startPanCard{
    if(self.StartPanCardBlock){
        self.StartPanCardBlock();
    }
}
//- (void)layoutSubviews{
//    [super layoutSubviews];
//    [self.dk_PanCardBgView makeCornerOnTopleftRight:DK_IsWidthScale(50)];
//}
//-(void)layoutSublayersOfLayer:(CALayer *)layer{
//    [super layoutSublayersOfLayer:layer];
//    [self.dk_PanCardBgView makeCornerOnTopleftRight:DK_IsWidthScale(50)];
//}
@end
